<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;

class GoodsListController extends  Controller{
	private $GoodsAttrModel;
	private $GoodsListModel;
	
	public function __init(){
		$this->GoodsAttrModel=M('\Common\Model\sc_goods_attr');
		$this->GoodsListModel=M('\Common\Model\sc_goods_list');
		if(!isset($_SESSION['info'])){
			go('Logo/index');
		}
	}
	

	public function index(){
		
		if(IS_POST){
			if($this->GoodsListModel->addGoodsList()) View::success('添加成功！');
			View::error($this->GoodsListModel->getError());
		}

		//通过gid获取商品属性和类型属性
		$GoodsListAttrData=$this->GoodsAttrModel->getGoodsListAttr();
		View::with('GoodsListAttrData',$GoodsListAttrData);
		
		//通过gid获取货品列表详情
		$GoodsListData=$this->GoodsListModel->getGoodsList();
		
		View::with('GoodsListData',$GoodsListData);
		
		
		View::make();
	}
	
	
	//异步判断货品是否存在
	public function check(){
		$gid=Q('get.gid');
		$combine=implode(",", Q('get.combine'));
		echo $this->GoodsListModel->where("combine = '{$combine}'")->count()?0:1;
		
	}
	
	
	
	
	
}
